﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AppNet.Service;
using AppNet.Models;
using AppNet.MultiLanguage;

namespace AppNet.Controllers
{
    [SetCulture(CultureStore = SetCultureAttribute.CultureLocation.Session, SessionParamName = "culture")]
    public class HomeController : Controller
    {
        private AppNetDBContext db = new AppNetDBContext();

        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            return View();
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Category cat)
        {
            if (ModelState.IsValid)
            {
                cat.CategoryLangs.First().Lang = Translation.GetInstance.Culture;
                db.Categories.Add(cat);
                db.SaveChanges();
            }
            return RedirectToAction("Index");  
        }

        public ActionResult Language(string culture)
        {
            Session["culture"] = culture;
            return RedirectToAction("Index");  
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
